<?php
class Alertas extends CI_Controller {
	
	
	
  //comment from web 
function index($idObra)
{
	
	
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');

$this->load->model('Alerta_modelo','','TRUE');
$this->load->model('Subcontrata_modelo','','TRUE');



$this->form_validation->set_rules('nombre', 'Nombre', 'required');
$this->form_validation->set_rules('apellidos', 'Apellidos', 'required');
$this->form_validation->set_rules('nivel', 'Nivel', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');


$niveles=$this->Alerta_modelo->listado_niveles();

foreach($niveles as $item){
	
	$nvl[]= array ('idNivelA'=>$item->idNivelA,'nivelAlerta'=>$item->nivelAlerta);
}

$data['niveles']=$nvl;

$data['subcons']=$this->Subcontrata_modelo->subcons();

$data['idObra']=$idObra;


            


if ($this->form_validation->run() == FALSE)
{
$this->load->view('form_alertas',$data);



}
else {

$this->load->view('form_alertas_ok',$data);
$this->Alerta_modelo->insertar_alerta($idObra);


}


	}
	
	
	
	
	
	function modificar_alerta($idAlerta){
		
		
	
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');

$this->load->model('Alerta_modelo','','TRUE');
$this->load->model('Subcontrata_modelo','','TRUE');



$this->form_validation->set_rules('nombre', 'Nombre', 'required');
$this->form_validation->set_rules('apellidos', 'Apellidos', 'required');
$this->form_validation->set_rules('nivel', 'Nivel', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
		
		
	$niveles=$this->Alerta_modelo->listado_niveles();	
	
	
foreach($niveles as $item){
	
	$nvl[]= array ('idNivelA'=>$item->idNivelA,'nivelAlerta'=>$item->nivelAlerta);
}

$data['niveles']=$nvl;

$data['subcons']=$this->Subcontrata_modelo->subcons();

$data['alertas']=$this->Alerta_modelo->datos_alerta($idAlerta);
$data['idAlerta']=$idAlerta;

	       


if ($this->form_validation->run() == FALSE)
{
$this->load->view('form_alertas_modi',$data);



}
else {

$this->load->view('form_alertas_modi_ok',$data);
$this->Alerta_modelo->modificar_alerta($idAlerta);


}


		
		
	}
	
	
	
	
	
	
}